import fetch from 'common/src/utils/fetch';
import cryp from  'common/src/utils/secret';
import UTILS from "common/src/utils/utils";
// 学籍
export function findStuInfoList(data) {
    return fetch({
        url: '/api/studentservice/studentInfo/findStuInfoList',
        method: 'post',
        headers: {
            'Content-Type': 'application/json'
        },
        data
    });
}

// 英语学生能力
export function findStuInfoListByEnglishTeacher(data) {
    return fetch({
        url: '/api/studentservice/studentInfo/findStuInfoListByEnglishTeacher',
        method: 'post',
        headers: {
            'Content-Type': 'application/json'
        },
        data
    });
}

/**
 * 使用pageCondition的分页查询url
 */
export const findStuInfoPageUrl =
  '/api/studentservice/studentInfo/findStuInfoPage';
/**
 * 导出学生基本信息列表
 * @param {Object} params
 */
export function findStuInfoListExport(params) {
    let url = '/api/studentservice/studentInfo/findStuInfoListExport';
    let remove_params = ['pageNum_', 'pageSize_'];
    let queryParam = '';
    for (let key in params) {
    // 去掉分页
        if (remove_params.includes(key)) {
            continue;
        }
        // 去掉空参数
        if (params[key] == '') {
            continue;
        }
        queryParam += `${key}=${params[key]}&`;
    }
    window.open(`${url}?${queryParam}`);
}

/**
 * 查询学生可见信息
 * @param data
 */
export function getStudentInfo(data) {
    return fetch({
        url: '/api/studentservice/studentInfo/findViewColumnByTable',
        method: 'post',
        data
    });
}

// 获取学生个人信息
export function statusInfo (studentId) {
    return fetch({
        url:  `/api/studentservice/apply/statusInfo?studentId=${studentId}`,
        method: 'get',
    });
}

/**
 * 学籍字典查询接口
 */
export function getFieldsByTableName(query) {
    return fetch({
        url: '/api/studentservice/studentDic/getByTableName?' + query,
        method: 'get'
    });
}

/**
 * 查询学籍配置列表, 可见 可写列表
 */
export function getOperatesOfField() {
    return fetch({
        url: '/api/studentservice/configOptions/getConOptList',
        method: 'get'
    });
}

/**
 * 保存各字段的配置（可见可改等配置）
 */
export function saveOperatesOfField(data) {
    return fetch({
        url: '/api/studentservice/configOptions/saveConfigInfo',
        method: 'post',
        data
    });
}

/**
 * 根据表名查询配置信息（可见可改等配置）
 */
export function getConfigInfo(query) {
    return fetch({
        url: '/api/studentservice/configOptions/getConfigInfo?' + query,
        method: 'get'
    });
}

/**
 * 查询可编辑字段
 * @param data
 */
export function getEidtColumn(data) {
    return fetch({
        url: '/api/studentservice/studentInfo/findEidtColumn',
        method: 'post',
        data
    });
}

export function getAllColumn(options) {
    let allColumn = getStudentInfo(options);
    let editColumn = getEidtColumn(options);
    let getAllColumn = new Promise((resolve, reject) => {
        Promise.all([allColumn, editColumn]).then(res => {
            resolve(res);
        });
    });
    return getAllColumn;
}

/**
 * 单表保存可编辑值
 * @param data
 */
export function saveEdit(data) {
    return fetch({
        url: '/api/studentservice/studentInfo/saveEditColumnVal',
        method: 'post',
        data
    });
}

/**
 * 查询院审或者校审可编辑字段以及值
 * @param params
 */
export function getEidtAcaEduColumn(params) {
    return fetch({
        url: '/api/studentservice/studentInfo/findEidtAcaEduColumn/',
        method: 'get',
        params: params
    });
}

/**
 * 保存院审或者校审所有值
 * @param data
 */
export function saveEditAcaEduColumnVal(data) {
    return fetch({
        url: '/api/studentservice/studentInfo/checkEditAcaEduColumnVal',
        method: 'post',
        data
    });
}

/**
 * 查询教师列表
 * @param {data} data
 */
export function findTeacherInfoList(data) {
    return fetch({
        url: '/api/studentservice/teacherInfo/findTeacherInfoList',
        method: 'post',
        headers: {
            'Content-Type': 'application/json'
        },
        data
    });
}
export function findTeacherSelectList(data) {
    return fetch({
        url: '/api/studentservice/teacherInfo/findSelectList',
        method: 'post',
        headers: {
            'Content-Type': 'application/json'
        },
        data
    });
}
/**
 * 查询教育背景列表
 * @param studentId
 */
export function getEduBackgroudList(studentId) {
    return fetch({
        url: '/api/studentservice/studentEduBackg/findEduBackgroudList',
        method: 'get',
        params: {
            studentId: studentId
        }
    });
}

/**
 * 查询单个教育背景
 * @param ideee
 */
export function getEduBackgroud(id) {
    return fetch({
        url: '/api/studentservice/studentEduBackg/findEduBackgroud',
        method: 'get',
        params: {
            id: id
        }
    });
}

/**
 * 新增教育背景
 * @param data
 */
export function addEduBackgroud(data) {
    return fetch({
        url: '/api/studentservice/studentEduBackg/addEduBackgroud',
        method: 'post',
        data
    });
}

/**
 * 修改教育背景
 * @param data
 */
export function updateEduBackgroud(data) {
    return fetch({
        url: '/api/studentservice/studentEduBackg/updateEduBackgroud',
        method: 'post',
        data
    });
}

/**
 * 删除教育背景
 * @param id
 */
export function deleteEduBackgroud(id) {
    return fetch({
        url: '/api/studentservice/studentEduBackg/deleteEduBackgroud',
        method: 'delete',
        params: {
            id: id
        }
    });
}

/**
 * 获取所有异动设置
 * @param data
 */
export function getAbnormalList(data) {
    return fetch({
        url: '/api/studentservice/abnormal/template',
        method: 'post',
        data
    });
}

/**
 * 学籍异动申请
 * @param data
 */
export function abnormalApply(data) {
    return fetch({
        url: '/api/studentservice/abnormal/apply',
        method: 'post',
        data
    });
}

/**
 * 学籍异动申请
 * @param data
 */
export function abnormalUpdate(data) {
    return fetch({
        url: '/api/studentservice/abnormal/template',
        method: 'put',
        data
    });
}
/**
 * 下载学生权限字段模板
 */
export function downloadTemplate() {
    return '/api/studentservice/configOptions/downloadTemplate';
}
/**
 * 学生详情查询
 */
export function getStudentDetail(data) {
    if(data.studentId) {
        data.studentId = cryp.encrypt(data.studentId)
    }
    return fetch({
        url: '/api/studentservice/studentDetailInfo/stuDetailByClass',
        method: 'post',
        data
    });
}
/**
 * 获取专业方向名称接口
 */
export function getMajorDirectionNames(data) {
    let str = String(data)
    return fetch({
        url: '/api/studentservice/studentDetailInfo/findDirectionMaintenByCode/' + str,
        method: 'GET'
    });
}
/**
 * 学生详情提交
 */
export function stuDetailSubmit(data) {
    return fetch({
        url: '/api/studentservice/studentDetailInfo/stuDetailSubmit',
        method: 'post',
        data
    });
}
/**
 * 字段院审、校审配置角色查询
 */
export function getApproRoles(data) {
    return fetch({
        url: '/api/studentservice/configOptions/getApproRoles',
        method: 'post',
        data
    });
}
/**
 * 字段配置角色下人员
 */
export function getApproUser(roleId, type, configId) {
    return fetch({
        url: '/api/studentservice/configOptions/getApproUser?roleId=' +
      roleId +
      '&type=' +
      type +
      '&configId=' +
      configId,
        method: 'get'
    });
}
/**
 * 角色人员的配置字段信息
 */
export function getApproFields(data) {
    return fetch({
        url: '/api/studentservice/configOptions/getApproFields',
        method: 'post',
        data
    });
}
/**
 * 角色人员的配置字段信息
 */
export function addFieldRoleConfig(data) {
    return fetch({
        url: '/api/studentservice/configOptions/addFieldRoleConfig',
        method: 'post',
        data
    });
}
/**
 * 学生指定导师列表
 */
export function getAppointList(data) {
    return fetch({
        url: '/api/studentservice/stuAppoint/getAppointList',
        method: 'post',
        data
    });
}
/**
 * 无导师学生列表
 */
export function getNoAppointStuList(data) {
    return fetch({
        url: '/api/studentservice/stuAppoint/getNoAppointStuList',
        method: 'post',
        data
    });
}
/**
 * 选中无导师学生
 */
export function selectedStu(data) {
    return fetch({
        url: '/api/studentservice/stuAppoint/selectedStu',
        method: 'post',
        data
    });
}
/**
 * 导师列表
 */
export function getAppointTeaList(data) {
    return fetch({
        url: '/api/studentservice/stuAppoint/getAppointTeaList',
        method: 'post',
        data
    });
}
/**
 * 指定导师
 */
export function appointTea(data) {
    return fetch({
        url: '/api/studentservice/stuAppoint/appointTea',
        method: 'post',
        data
    });
}
/**
 * 撤销导师
 */
export function deleteAppointTea(data) {
    return fetch({
        url: '/api/studentservice/stuAppoint/deleteAppointTea',
        method: 'post',
        data
    });
}
/**
 * 删除学生名单
 */
export function deleteStuAppointed(id) {
    return fetch({
        url: '/api/studentservice/stuAppoint/deleteStuAppointed?id=' + id
    });
}
/**
 * 下载导入模板
 */
export function downloadStuTemplate() {
    return '/api/studentservice/stuAppoint/downloadTemplate';
}
/**
 * 导出学生名单
 */
export function exportAppointListExcel(query) {
    let params = '';
    for (let key in query) {
        if (query[key]) {
            params += key + '=' + query[key] + '&&';
        }
    }
    let url = '/api/studentservice/stuAppoint/exportAppointListExcel?' + params;
    return fetch({
        url: url,
        showMask: false
    });
}

/**
 * 新增信息激活设置
 */
export function addConfig(data) {
    return fetch({
        url: '/api/studentservice/stuActivation/addConfig',
        method: 'post',
        data
    });
}
/**
 * 查询信息激活设置
 */
export function configList(data) {
    return fetch({
        url: '/api/studentservice/stuActivation/configList',
        method: 'post',
        data
    });
}
/**
 * 获取单个信息激活设置
 */
export function getConfig(configId) {
    return fetch({
        url: '/api/studentservice/stuActivation/getConfig?configId=' + configId
    });
}
/**
 *  修改信息激活设置
 */
export function updateConfig(data) {
    return fetch({
        url: '/api/studentservice/stuActivation/updateConfig',
        method: 'post',
        data
    });
}
/**
 * 删除信息激活设置
 */
export function deleteConfig(configId) {
    return fetch({
        url: '/api/studentservice/stuActivation/deleteConfig?configId=' +
      configId,
        method: 'get'
    });
}
/**
 * 获取字段类型
 */
export function fieldType() {
    return fetch({
        url: '/api/studentservice/stuActivation/fieldType'
    });
}
/**
 * 获取字段类型下的所有字段信息
 */
export function fieldsByfieldType(fieldClasses) {
    return fetch({
        url: '/api/studentservice/stuActivation/fieldsByfieldType?fieldClasses=' +
      fieldClasses
    });
}
/**
 *  字段设置
 */
export function fieldConfig(data) {
    return fetch({
        url: '/api/studentservice/stuActivation/fieldConfig',
        method: 'post',
        data
    });
}
/**
 *  查询单个配置中的字段信息
 */
export function singleConfig(data) {
    return fetch({
        url: '/api/studentservice/stuActivation/singleConfig',
        method: 'post',
        data
    });
}

/**
 *  学生激活配置信息列表
 */
export function activationList(data) {
    return fetch({
        url: '/api/studentservice/stuActivation/activationList',
        method: 'post',
        data
    });
}
/**
 *  学生激活信息名单列表
 */
 export function studentListByConfig(data) {
    return fetch({
        url: '/api/studentservice/stuActivation/studentListByConfig',
        method: 'post',
        data
    });
}
/**
 * 导出学生激活列表
 */
export function exportactivationList(query) {
    let params = '';
    for (let key in query) {
        if (
            query[key] &&
      key !== 'pageSize_' &&
      key !== 'pageNum_' &&
      query[key].length !== 0
        ) {
            params += key + '=' + query[key] + '&&';
        }
    }
    return '/api/studentservice/stuActivation/exportactivationList?' + params;
}
// 激活学生名单列表导出
export function exportStudentListByConfig(query) {
    let params = '';
    for (let key in query) {
        if (
            query[key] &&
      key !== 'pageSize_' &&
      key !== 'pageNum_' &&
      query[key].length !== 0
        ) {
            params += key + '=' + query[key] + '&&';
        }
    }
    return '/api/studentservice/stuActivation/exportStudentListByConfig?' + params;
}
/**
 *  院审/校审字段审批
 */
export function colSchSubmit(data) {
    return fetch({
        url: '/api/studentservice/studentDetailInfo/colSchSubmit',
        method: 'post',
        data
    });
}

/**
 *  学生登录后弹出窗口信息
 */
export function checkActivation(studentId) {
    return fetch({
        url: '/api/studentservice/stuActivation/checkActivation?studentId=' +
      studentId
    });
}
/**
 *  学生确认完成信息后激活
 */
export function activation(data) {
    return fetch({
        url: '/api/studentservice/stuActivation/activation',
        method: 'post',
        data
    });
}

/**
 *  信息变更日志列表
 */
export function getLogList(data) {
    return fetch({
        url: '/api/studentservice/fieldLog/getLogList',
        method: 'post',
        data
    });
}

/**
 *  信息变更日志列表导出
 */
export function exportLogList(query) {
    let params = '';
    for (let key in query) {
        if (query[key]) {
            params += key + '=' + query[key] + '&&';
        }
    }
    return '/api/studentservice/fieldLog/exportLogList?' + params;
}

/**
 *  信息变更DBF导出
 */
export function exportChangeDbf(query) {
    let params = '';
    for (let key in query) {
        if (query[key]) {
            params += key + '=' + query[key] + '&&';
        }
    }
    return '/api/studentservice/fieldLog/exportChangeDbf?' + params;
}
/**
 *  学生详情--类别标签可见列表
 */
export function getVisibleTabList(studentId) {
    return fetch({
        url: '/api/studentservice/studentDetailInfo/getVisibleTabList?studentId=' +
      studentId,
        method: 'get'
    });
}

export function getAllApproFields(configId) {
    return fetch({
        url: '/api/studentservice/configOptions/getAllApproFields?configId=' +
      configId,
        method: 'get'
    });
}
/**
 * 获取所有学生信息字段
 */
export function findAllStuDicts() {
    return fetch({
        url: '/api/studentservice/studentDic/findAllStuDicts',
        method: 'get'
    });
}


/**
 * 查询学生下拉组件的接口
 * @param {*} data
 */
export function findStuInfoListForSelect(data, showMask) {
    return fetch({
        url: '/api/studentservice/studentInfo/findStuInfoListForSelect',
        method: 'post',
        headers: {
            'Content-Type': 'application/json'
        },
        showMask: showMask,
        data
    });
}

/**
 * 学生信息查询
 * @param {*} studentId 学号
 * @param {*} stuInfoClass 学生信息分类
 */
export function getStuInfoByParam(studentId, stuInfoClass) {
    return fetch({
        url: '/api/studentservice/studentDetailInfo/getStuInfoByParam?studentId=' + studentId + '&stuInfoClass=' + stuInfoClass
    });
}

export function getMajorImage(studentId) {
    return fetch({
        url: '/api/transformer/picture/queryPicture',
        method: 'post',
        data: {
            list: studentId
        }
    })
}

/**
 * 根据学号查询学籍详情
 * @param {*} studentId 学号
 */
export function getStatusInfoByStudentId(studentId) {
    return fetch({
        url: '/api/studentservice/studentDetailInfo/getStatusInfoByStudentId?studentId=' + studentId
    });
}
/**
 * 下载导入查询模板
 */
export function getImportTemplate() {
    return '/api/studentservice/studentInfo/downloadImportTemplate';
}
/**
 * 配置检查
 */
export function checkSelectedFile() {
    return fetch({
        url: '/api/studentservice/configOptions/checkSelectedFile',
        method: 'get'
    });
}
// 根据学位类型和培养层次获取相关字典
export function findStuDicLinkage(data) {
    return fetch({
        url: '/api/studentservice/studentDic/findStuDicLinkage',
        method: 'post',
        data
    });
}
/**
 * 获取学籍专业方向名称
 * @param {*} studentId
 */
export function getDirections(studentId) {
    return fetch({
        url: '/api/studentservice/studentDetailInfo/getDirections?studentId=' + studentId,
    });
}
/**
 * 获取火车站终点
 * @param {*} data
 */
export function getStationInfoList(data) {
    return fetch({
        url: '/api/studentservice/studentDetailInfo/getStationInfoList',
        method: 'post',
        data
    });
}

/**
 * 获取学籍专业
 * @param {*} data
 */
export function findStatusProfessionList(data) {
    return fetch({
        url: '/api/studentservice/studentInfo/findStatusProfessionList',
        method: 'post',
        data
    });
}

/**
 * 获取所有学院
 */
 export function allFacultyList() {
    return fetch({
        url: '/api/studentservice/apply/allFacultyList',
        method: 'get'
    });
}

/* 
    站点维护列表
*/
export function listStation(data) {
    return fetch({
        url: '/api/studentservice/station/listStation',
        method: 'post',
        headers: {
            'Content-Type': 'application/json'
        },
        data
    });
}
/* 
    省份下拉框
*/
export function selectStation() {
    return fetch({
        url: '/api/studentservice/station/selectStation',
        method: 'get'
    });
}

/* 
    编辑站点
*/
export function editStation(data) {
    return fetch({
        url: '/api/studentservice/station/editStation',
        method: 'post',
        headers: {
            'Content-Type': 'application/json'
        },
        data
    });
}
/* 
    下载模板
*/
export function downloadTemplates() {
    return fetch({
        url: '/api/studentservice/station/downloadTemplate',
        method: 'get',
        responseType: 'blob'
    }).then(res => {
        UTILS.downloadFile(res, '下载模板.xlsx', 'application/vnd.ms-excel;charset=utf-8');
    });
}
/* 
    批量导入接口
*/
export function importStation(data) {
    return fetch({
        url: '/api/studentservice/station/importStation',
        method: 'post',
        headers: {
            'Content-Type': 'application/json'
        },
        data
    });
}
/* 
    轮询结果
*/
export function getStuAppoint(key) {
    return fetch({
        url: `/api/studentservice/stuAppoint/result/${key}`,
        method: 'get'
    });
}
// 专业方向/行政班级学生列表
export function getMajorDirectionStus(data) {
    return fetch({
        url: '/api/studentservice/studentSetting/studentList',
        method: 'post',
        headers: {
            'Content-Type': 'application/json'
        },
        data
    });
}
// 设置专业方向名称-获取专业方向名称
export function getSetMajorDirectionNames(data) {
    return fetch({
        url: '/api/commonservice/directionMainten/findDirectionMaintenList',
        method: 'post',
        headers: {
            'Content-Type': 'application/json'
        },
        data
    });
}
// 添加/删除--专业方向/行政班级
export function updateMajorDirecStus(data) {
    return fetch({
        url: '/api/studentservice/studentSetting/updateStudentSetting',
        method: 'post',
        headers: {
            'Content-Type': 'application/json'
        },
        data
    });
}
// 获取行政班级
export function getAdminiClasses(data) {
    return fetch({
        url: '/api/commonservice/administrativeClass/query',
        method: 'post',
        headers: {
            'Content-Type': 'application/json'
        },
        data
    });
}

/* 
    新增或编辑学籍相关模板文件
*/
export function editTemplate(data) {
    return fetch({
        url: '/api/studentservice/templateFile/editTemplate',
        method: 'post',
        headers: {
            'Content-Type': 'application/json'
        },
        data
    });
}

/* 
    编辑模板说明
*/
export function editRemark(data) {
    return fetch({
        url: '/api/studentservice/templateFile/editRemark',
        method: 'post',
        headers: {
            'Content-Type': 'application/json'
        },
        data
    });
}

/* 
    学籍相关模板列表
*/
export function listTemplate(data) {
    return fetch({
        url: '/api/studentservice/templateFile/listTemplate',
        method: 'post',
        headers: {
            'Content-Type': 'application/json'
        },
        data
    });
}

/* 
    删除学籍相关模板列表
*/
export function delTemplate(data) {
    return fetch({
        url: '/api/studentservice/templateFile/delTemplate',
        method: 'post',
        headers: {
            'Content-Type': 'application/json'
        },
        data
    });
}

/* 
    学籍相关模板文件下载
*/
const downTemplate = (fileName, url) => {
    return fetch({
      url: url,
      method: 'get',
      responseType: "blob",
      timeout: 0
    }).then(res => {
      UTILS.downloadFile(
        res,
        fileName,
        fileName.substr(fileName.lastIndexOf(".") + 1)
      );
    });
  };

  /* 
    带文件名下载
*/
export function downloadExport(fileName, url){
    return fetch({
      url: url,
      method: 'get',
      responseType: "blob",
      timeout: 0
    }).then(res => {
      UTILS.downloadFile(
        res,
        fileName,
        'application/vnd.ms-excel;charset=utf-8'
      );
    });
  };

  // 编辑权限列表
export function queryEditControl(data) {
    return fetch({
        url: `/api/studentservice/configOptions/queryEditControl`,
        method: 'post',
        data
    });
}
  // 授权
export function addEditControl(data) {
    return fetch({
        url: `/api/studentservice/configOptions/addEditControl`,
        method: 'post',
        data
    });
}
  // 取消授权
export function deleteEditControl(data) {
    return fetch({
        url: `/api/studentservice/configOptions/deleteEditControl`,
        method: 'post',
        data
    });
}
// 根据年级和专业查询专业
export function findProsByFacultiesWithGrade(data) {
    return fetch({
        url: `/api/studentservice/StudentExport/query-professions`,
        method: 'get',
        params:data
    });
  }
  
// 新生导出名单
export function findViewColumnByTable(data) {
    return fetch({
        url: `/api/studentservice/StudentExport/findAllData`,
        method: 'post',
        data
    });
}
/* 
    导出封面
*/
export function exportFm(data) {
    return fetch({
        url: `/api/studentservice/StudentExport/exportFm?stuGrade=${data}`,
        method: 'get',
        responseType: 'blob'
    }).then(res => {
        UTILS.downloadFile(res, '封面.doc', 'application/msword;charset=utf-8');
    });
}
/* 
    导出专业目录
*/
export function exportStuDir(data) {
    return fetch({
        url: `/api/studentservice/StudentExport/exportStuDir?stuGrade=${data}`,
        method: 'get',
        responseType: 'blob'
    }).then(res => {
        UTILS.downloadFile(res, '专业目录.doc', 'application/msword;charset=utf-8');
    });
}
/* 
    导出新生名单
*/
export function exportStuList(data) {
    return fetch({
        url: `/api/studentservice/StudentExport/exportStuList?stuGrade=${data}`,
        method: 'get',
        data
    })
}
/* 
    导出新生名单2
*/
export function queryFileStatus(data) {
    return fetch({
        url: `/api/studentservice/StudentExport/queryFileStatus?key=${data}`,
        method: 'get',
        data
    })
}
  export default {
    downTemplate,
  };
 
